<?php

namespace App\Http\Controllers;

use App\Job;
use Illuminate\Http\Request;
use App\Rule;

class JobController extends Controller
{
    public function __construct() {
        $this->middleware('auth');
    }
    public function index()
    {
        $uid=\Auth::id();
        $rules=Rule::where('uid',$uid)->get();
        //  dd($rules);

        return view('worker.job',['rules'=>$rules]);
    }
    public function add(Request $request)
    {
        $adduser['name'] = $request->input('name');
        $adduser['wage'] = $request->input('wage');
        $adduser['notes'] = $request->input('notes');
        Job::create($adduser);
    }
    public function edit($id,Request $request)
    {
        $adduser = Job::find($id);
        $adduser->name = $request->input('name');
        $adduser->wage = $request->input('wage');
        $adduser->notes = $request->input('notes');
        $adduser->save();
    }
    public function del($id)
    {
        $user=Job::find($id);
        $user->delete();
    }
    public function getAll()
    {

        $jobs=Job::all();
        return response()->json($jobs);
        //  dd($rules);

    }
    public function getOne($id)
    {

        $jobs=Job::find($id);
        return response()->json($jobs);

    }


}
